package com.base.framework.admin.api.system;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.base.framework.admin.domain.Role;
import com.base.framework.admin.service.IRoleService;
import com.base.framework.common.response.ActionResponse;

@RestController
@RequestMapping("/system/role/")
public class RoleController {
	  @Autowired
	  private IRoleService roleService;
	  /*
	   * 功能：新增角色
	   */
	   @RequestMapping("add")
	   public ActionResponse<Boolean> add(Role role){
		   ActionResponse<Boolean> response=new ActionResponse<Boolean>();
		   role.setCreateTime(new Date());
		   //todo
		   //role.setCreateUserId(createUserId);
		   boolean isOk=roleService.insertSelective(role);
		   if(!isOk){
				response.failMessage("新增角色失败！");
				return response;
		   }
		   response.success(true);
		   return response;
	   }
	  /*
	   * 功能：查询角色
	   */
       public ActionResponse<Page<Role>> list(Page<Role> page){
    	   ActionResponse<Page<Role>> response=new ActionResponse<Page<Role>>();
    	   EntityWrapper<Role> entityWrapper=new  EntityWrapper<Role>();
    	   Page<Role> resultPage=roleService.selectPage(page, entityWrapper);
    	   response.success(resultPage);
    	   return response;
	   }
	  /*
	   * 功能：编辑角色
	   */
       public ActionResponse<Boolean> edit(Role role){
 		  ActionResponse<Boolean> response=new ActionResponse<Boolean>();
 		  boolean isOk=roleService.updateSelectiveById(role);
 		  if(!isOk){
 			  response.failMessage("编辑角色失败！");
 			  return response;
 		  }
 		  response.success(true);
 		  return response;
	   }
	  /*
	   * 功能：角色授权
	   */
       public void authorized(){
		   
	   }
}
